<table width="100%" border="0">
  <tr>
    <td width="120px;" valign="top" height="400px">
    <div style=" text-align:center;">
        <?php 
		if($f == 1){
		?>
        <a href="#" class="easyui-linkbutton" onClick="save_copy_doc(0)" style="width:95%; margin-top:2px; padding:5px 0px;">保存文件</a>
        <a href="#" class="easyui-linkbutton" onClick="save_copy_doc(1)" style="width:95%; margin-top:2px; padding:5px 0px;">保存并关闭</a>
        
		<a href="#" class="easyui-linkbutton" onClick="set_track_revisions(1)" style="width:95%; margin-top:2px; padding:5px 0px;">保留痕迹</a>
        <a href="#" class="easyui-linkbutton" onClick="set_track_revisions(0)" style="width:95%; margin-top:2px; padding:5px 0px;">不留痕迹</a>
        
        <a href="#" class="easyui-linkbutton" onClick="show_revisions(1)" style="width:95%; margin-top:2px; padding:5px 0px;">显示痕迹</a>
        <a href="#" class="easyui-linkbutton" onClick="show_revisions(0)" style="width:95%; margin-top:2px; padding:5px 0px;">隐藏痕迹</a>
        
        <a href="#" class="easyui-linkbutton" onClick="insert_file(1)" style="width:95%; margin-top:2px; padding:5px 0px;">插入签名</a>
		<?php }else{ ?>
        <a href="#" class="easyui-linkbutton" onClick="set_close()" style="width:95%; margin-top:2px; padding:5px 0px;">关闭</a>
        <a href="#" class="easyui-linkbutton" onClick="show_revisions(1)" style="width:95%; margin-top:2px; padding:5px 0px;">显示痕迹</a>
        <a href="#" class="easyui-linkbutton" onClick="show_revisions(0)" style="width:95%; margin-top:2px; padding:5px 0px;">隐藏痕迹</a>
        <?php } ?>
    </div>
    </td>
    <td>
    <div id="framdoc">
        <object classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" id="oframe" align='middle' codebase="<?php echo base_url();?>data/oc/dsoframer.ocx#version=2,3,0,0" height="100%" width="100%" >
            <param name="BorderStyle" value="1">
            <param name="Titlebar" value="0">
            <param name="TitlebarColor" value="52479">
            <param name="TitlebarTextColor" value="0">
            <param name="Menubar" value="0">
        </object>
    </div>
    </td>
  </tr>
</table>

<script>
var getfram = document.getElementById("framdoc");
var h = document.body.offsetHeight;
getfram.style.height = (h-45)+'px';

function ole_type_fun(v){
	var str = '';
	var att_suffix = interception_suffix(v);
	att_suffix = att_suffix[0].toLowerCase();
	
	if(att_suffix == ".doc" || att_suffix == ".docx"){
		str = "Word.Document";
	}else if(att_suffix == ".xls" || att_suffix == ".xlsx"){
		str = "Excel.Sheet";
	}
	return str;
}
var ole_type_str = ole_type_fun('<?php echo $att_name;?>');

function open_word(){
	//var ole_type = ole_type_fun(name);
	document.all.oframe.open('<?php echo base_url()."attachment/att_down?m=".$m.'&att_id='.$att_id.'&att_name='.$att_name;?>',true,ole_type_str);
	if(<?php echo $f;?> == 0){
		document.all.oframe.ProtectDoc(1, 1, "pwd");//只能阅读，不能编辑，但可以复制
	}
	//document.all.oframe.ProtectDoc(1, 2, "pwd");//只能阅读，不能编辑和复制
	//oframe.CreateNew("Excel.Sheet");
}
open_word();

//保存并关闭文档
function save_copy_doc(v){
	//初始化Http引擎
	document.all.oframe.HttpInit();
	//增加Post变量
	document.all.oframe.HttpAddPostString("url","<?php echo $m.'/'.$date_rand[0].'/'.$date_rand[1].'.';?>");
	//document.all.oframe.HttpAddPostString("filename","dd");
	//上传打开的文件
	document.all.oframe.HttpAddPostCurrFile("FileData", "<?php echo urldecode($att_name);?>");
	//执行上传动作
	var data = document.all.oframe.HttpPost("<?php echo base_url('attachment/save_copy_doc');?>"); 
	var dataobj=eval("("+data+")");//转换为json对象
	if (!dataobj.status){
		alert('保存失败！');
	}else{
		alert('文件 <?php echo urldecode($att_name);?> 保存成功！');
		if(v == 1){
			document.all.oframe.close();
			$('#window_custom_box').window('close');
		}
	}
}

function set_close(){
	document.all.oframe.close();
	$('#window_custom_box').window('close');	
}

//显示隐藏痕迹
function show_revisions(v){
	document.all.oframe.ShowRevisions(parseInt(v));
}
show_revisions(0);

//是否启用留痕状态
function set_track_revisions(v){
	document.all.oframe.SetTrackRevisions(parseInt(v));
	
	//设置当前用户
	document.all.oframe.SetCurrUserName("<?php echo $this->session->userdata('user_name');?>");  
}
set_track_revisions(1);

//另存为文档
function save_copy_doc_local(){
	try{
		oframe.showdialog(3);
	}catch(Ex){
		alert("当前没有已打开文档.");
	}
}

//插入签名
function insert_file(v){
	if(v == 1){//插入图片
		//document.all.oframe.InSertFile("<?php echo base_url().'attach/signature/'.$this->session->userdata('user_name').'.jpg';?>",8);	
		document.all.oframe.InSertFile("<?php echo base_url().'attach/signature/'.$this->session->userdata('user_name');?>.doc",0);
	}
	if(v == 2){//文件套红
		
		//document.all.oframe.InSertFile("d:\\222.doc",0);
	}
}
</script>
